package com.jyuxuan.recruitment.mapper;

import com.jyuxuan.recruitment.pojo.Demand;
import com.jyuxuan.recruitment.pojo.Enterprise;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface DemandMapper {

    @Insert("Insert into demand(dname,ename,college,major,education,salary,need,enterpriseId,state) values(#{dname},#{ename},#{college},#{major},#{education},#{salary},#{need},#{enterpriseId},#{state})")
    public int save(Demand demand);

    @Update("Update demand set dname=#{dname},ename=#{ename},college=#{college},major=#{major},education=#{education},salary=#{salary},need=#{need},state=#{state} where demandId=#{demandId}")
    public int update(Demand demand);

    @Delete("Delete from demand where demandId=#{demandId}")
    public int delete(Demand demand);

    @Select("Select * from demand where demandId=#{dId}")
    public Demand findById(int dId);

    @Select("Select * from demand where enterpriseId=#{eId}")
    public List<Demand> findByEid(int eId);

    @Select({"<script>",
            "Select * from demand",
            "<where>",
            "<if test='dname != null'> ",
            "and dname=#{dname} ",
            "</if>",
            "<if test='ename != null'> ",
            "and ename=#{ename} ",
            "</if>",
            "<if test='college != null'> ",
            "and college=#{college} ",
            "</if>",
            "<if test='major != null'> ",
            "and major=#{major} ",
            "</if>",
            "<if test='education != null'> ",
            "and education=#{education} ",
            "</if>",
            "<if test='salary != null'> ",
            "and salary=#{salary} ",
            "</if>",
            "<if test='need != null'> ",
            "and need=#{need} ",
            "</if>",
            "<if test='state != null'> ",
            "and state=#{state} ",
            "</if>",
            "</where>",
            "order by demandId",
            "</script>"})
    public List<Demand> findDynamic(Demand demand);
}
